package cn.edu.zafu.bigdata.smj;

import java.util.HashMap;

public class TestStudentGradeManager {
    public static void main(String[] args) {
        // 创建StudentGradeManager对象
        StudentGradeManager manager = new StudentGradeManager();

        // 添加几个学生成绩
        manager.addStudent("Alice", 90);
        manager.addStudent("Bob", 85);
        manager.addStudent("Charlie", 95);

        // 查询学生成绩
        System.out.println("Alice's grade: " + manager.getGrade("Alice")); // 应该输出90
        System.out.println("Bob's grade: " + manager.getGrade("Bob")); // 应该输出85
        System.out.println("Charlie's grade: " + manager.getGrade("Charlie")); // 应该输出95
        System.out.println("David's grade: " + manager.getGrade("David")); // 不存在，应该输出-1

        // 删除一个学生成绩
        manager.removeStudent("Bob");
        System.out.println("Bob's grade after removal: " + manager.getGrade("Bob")); // 应该输出-1，因为Bob已被删除
    }

    public static class StudentGradeManager {
        private HashMap<String, Integer> studentGrades;
        public StudentGradeManager() {
            studentGrades = new HashMap<>();
        }

        // 添加学生成绩
        public void addStudent(String name, int grade) {
            studentGrades.put(name, grade);
        }

        // 根据学生姓名获取成绩
        public int getGrade(String name) {
            // 如果学生姓名不存在，则返回-1
            return studentGrades.getOrDefault(name, -1);
        }

        // 删除学生成绩
        public void removeStudent(String name) {
            studentGrades.remove(name);
        }

    }
}
